<!---
	Title:		Application.cfc for Intranet
	Author:		Michael Lewis
	Purpose:	Special simplified application.cfc for Intranet.
	Version:	1.0
	History:	1.0 - Original Working Version.
				0.0 - Preliminary.
--->

<cfcomponent output="false">

	<!--- *** REQUIRED ***
		  Application name, should be unique at SCF.  Available within your application as APPLICATION.ApplicationName.
		  Where practical, make this name the same as your Database and CF Data Source. --->
	<cfset THIS.name = "Intranet">


	<!--- *** REQUIRED ***
		 (We decided to make this REQUIRED in order to give us a way to track which users are using the app on a given day.)
		  Setting sessionManagement to true enables sessions (otherwise SESSION. does not work), while sessionTimeout
		  determines how long SESSION. values will persist, if not cleared.  Default timeout is 9 hours, and maximum
		  is 2 days (both of which are configured in CFAdmin).
	 --->
	<cfset this.sessionManagement = true>
	<cfset this.sessionTimeout = createTimeSpan(0,9,0,0)>

	<cffunction name="onApplicationStart" returnType="boolean" output="false">
	
		<cflock name="AppReset" type="exclusive" timeout="10">
			<cfif !(IsDefined("APPLICATION.qryExchangeErrors")) >
				<cfset APPLICATION.qryExchangeErrors = QueryNew('TimeOfError', 'Date') />
			</cfif>
		</cflock>
	
		<cfreturn true />
	</cffunction>


	<!--- onSessionStart() - Runs when each session starts.  ENABLE WHEN NEEDED. --->
	<cffunction name="onSessionStart" returnType="void" output="false">
	
		<cfif !IsDefined("SCF_Employee_GetEmployee")>
			<cfinclude template="/code_lib/SCF_Employee.cfm" />
		</cfif>	
	
		<cfset SESSION.myUserInfo = SCF_Employee_GetEmployee(CGI.REMOTE_USER) />
	</cffunction>


	<!--- onRequestStart() - Runs before each .cfm page request is processed. --->
	<cffunction name="onRequestStart" returnType="boolean" output="false">
		<cfargument name="thePage" type="string" required="true">

		<!--- Just in case it got missed (sometimes happens on server restart). --->		
		<cfif !(IsDefined("SESSION.myUserInfo"))>
			<cfset onSessionStart()>
		</cfif>
		
		<!--- <cfset onApplicationStart() /> --->

		<cfreturn true />
	</cffunction>


	<!--- *** REQUIRED ***   Of course, you'll want to comment this out while in development. --->
	<!--- onError() - Runs on any error.  This is a way to customize global error-handling throughout your app, and 
					  overrides the settings in CFAdmin: Settings.  In the future, this will use the SCF Application
					  database. 
	<cffunction name="onError" returnType="void" output="TRUE">
		<cfargument name="Exception" required="true">
		<cfargument name="EventName" type="string" required="true">
		
		<!--- developerEMail will eventually come from the SCF Application database.  For now, type in your own. --->
		<cfset var developerEMail = "SCFAppNotifyAdmin@scf.cc" />
		
		
		<!--- Create Log Entry --->
		<cflog type="error" text="#UCase(Exception.Type)# ERROR:  #Exception.Message#    LOCATION: #CGI.SERVER_NAME##CGI.SCRIPT_NAME#, Line #Exception.TagContext[1].Line#." />
		
		<!--- Send E-Mail to Developer --->
		<cfmail type="html" from=""" Your Friendly ColdFusion Server"" <noreply@scf.cc>" to="#developerEMail#"  subject="Doh! Error in #APPLICATION.ApplicationName#">

			<cfinclude template="/code_lib/SCF_Standard_Error_EMail.cfm" />
		</cfmail>
		
		<cfinclude template="/code_lib/SCF_Standard_Error_Display.cfm" />
		
		<!--- *** OPTIONAL - If you just want to throw the regular CF Error--for troubleshooting, perhaps--enable the 
							 line below. --->
		<cfthrow object="#ARGUMENTS.Exception#" />
		
	</cffunction>
	--->
    
    

</cfcomponent>